using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson12 : MonoBehaviour
{
    public Transform target;

    public float headoffSeth=1;

    public float angle = 45;

    public float dis = 5;
    public float mindis = 3;
    public float maxdis = 10;

    private Vector3 nowposition;
    private Vector3 nowDir;

    public float RotateSpeed = 5;
    public float MoveSpeed = 5;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        dis += Input.GetAxis("Mouse ScrollWheel");
        dis=Mathf.Clamp(dis, mindis, maxdis);

        nowposition = target.position + target.up * headoffSeth;
        nowDir = Quaternion.AngleAxis(angle, target.right) * -target.forward;
        nowposition = nowposition +  nowDir* dis;
        this.transform.position = Vector3.Lerp(this.transform.position, nowposition, Time.deltaTime*MoveSpeed);
        this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(-nowDir), Time.deltaTime*RotateSpeed);
    }
}
